import { loginApi } from '@/api/user'
const state = {
  token: '',
  time: 0
}

const mutations = {
  setToken(state, token) {
    state.token = token
  },
  removeToken(state) {
    state.token = null
    state.time = 0
  },
  updateTime(state, time) {
    state.time = time
  }
}

const actions = {
  async loginAction({ commit }, data) {
    const res = await loginApi(data)
    console.log(res, '11这里面的结果是什么')
    commit('setToken', res.token)
    // 此时state.token已经有了
    const time = Date.now()
    commit('updateTime', time)
  },
  logoutAction({ commit }) {
    commit('removeToken')
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}

